﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Book
{
   public class DbHelper
    {
        public static readonly string conStr = "Server=.;uId=sa;pwd=123456;database=Book;";

        public static DataTable GetSelect(string sql)
        {
            SqlConnection sqlcon = new SqlConnection(conStr);

            SqlDataAdapter sqlData = new SqlDataAdapter(sql, sqlcon);

            DataTable dt = new DataTable();

            sqlcon.Open();

            sqlData.Fill(dt);

            return dt;
        }

        public static int GetAddOrDelOrUp(string sql)
        {
            SqlConnection sqlcon = new SqlConnection(conStr);

            SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
            
            sqlcon.Open();

            int res = sqlcom.ExecuteNonQuery();

            return res;
        }
    }
}
